package com.webboard
import com.authen.User

class Post {
    static searchable = {           // <-- Make Comments searchable
        alias "foobar"
        except = ['id', 'version','postDate','count_reply']
    }
    String title
    String username
    String text
    Date postDate
    static hasMany = [replies:Reply]
    static belongsTo = [user:User]
    //Use to count Number of Reply
    int count_reply = 0;
    String ipAddress_client
    
    def listReplyOfId(post){
      return Reply.withCriteria {
        eq("post", post)
        order('id','asc') // 'asc' or  'desc'
      }
    }
    static constraints = {
        title(blank:false,minSize:5,maxSize:50)
        username(blank:false,maxSize:30)
        text(blank:false,minSize:10)
        user(nullable:true)
    }
}
